package threading;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @author 徐志荣
 * @date 2023/3/21 19:38
 */
public class ThreadDemo22 {
    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello5");
            }
        },5000);


        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello4");
            }
        },4000);



        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello3");
            }
        },3000);



        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello2");
            }
        },2000);



        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello1");
            }
        },1000);
        System.out.println("hello0");
        /*
        * Timer 里面内置了线程,(还是前台线程)会阻止进程结束~
        * */

        /*hello0
        hello1
        hello2
        hello3
        hello4
        hello5
        */
    }
}
